package com.aitaoxue.palx.fragment;

import java.util.Map;

import android.content.Intent;
import android.view.View;
import android.widget.AdapterView;

import com.aitaoxue.palx.adapter.MyCustomerAdapter;
import com.aitaoxue.palx.api.remote.AitaoXueApi;
import com.aitaoxue.palx.base.ListBaseAdapter;
import com.aitaoxue.palx.base.NoCacheBaseListFragment;
import com.aitaoxue.palx.bean.Customer;
import com.aitaoxue.palx.bean.CustomerList;
import com.aitaoxue.palx.bean.ListEntity;
import com.aitaoxue.palx.ui.ErrorBookActivity;
import com.aitaoxue.palx.util.GsonUtil;

public class ErrorBookListFragment extends NoCacheBaseListFragment {

	private static final String TAG = ErrorBookListFragment.class
			.getSimpleName();

	@Override
	protected ListBaseAdapter getListAdapter() {
		return new MyCustomerAdapter();
	}

	@Override
	protected ListEntity parseList(byte[] response) throws Exception {
		String res = new String(response);

		CustomerList list = GsonUtil.GsonToBean(res, CustomerList.class);

		return list;
	}

	@Override
	protected void sendRequestData(Map<String, String> map) {
		AitaoXueApi
				.getCustomerInfo(String.valueOf(mCurrentPage), mCacheHandler);
	}

	@Override
	public void onItemClick(AdapterView<?> parent, View view, int position,
			long id) {
		Customer customer = (Customer) mAdapter.getItem(position);
		Intent intent = new Intent(getActivity(), ErrorBookActivity.class);
		intent.putExtra("userid", customer.getUser_id());
		startActivity(intent);
	}
}
